package com.example.demo.repository;

import com.example.demo.domain.Address;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @author WaterTiger
 * @since 2020/6
 */
@Mapper
@Repository
public interface AddressMapper
{



    @Insert("insert into address (address, times, uid) " +
            "values ( #{address}, #{times}, #{uid})")
    public void addAddress(
            @Param("id") int id,
            @Param("address") String address,
            @Param("times") String times,
            @Param("uid") int uid
    );

    @Delete("delete from address where id = #{id}")
    public void delAddressById(@Param("id") int id);

    @Select("select * from address where id = #{id}")
    public Address getOnlyAddressById(Integer id);

    @Select("select * from address where uid = #{uid}")
    List<Address> getAddressByUid(Integer uid);

    @Insert("insert into address(address,uid,times) values(#{address},#{uid},#{times})" )
    void addPartAddress(@Param("address") String address,@Param("uid")Integer uid,@Param("times") String times);


    public Address getAddressById(Integer id);

    @Update("update address set " +
            "address = #{address}, " +
            "times = #{times}, " +
            "uid = #{uid} " +
            "where id = #{id}")
    public void saveAddress(
            @Param("id") int id,
            @Param("address") String address,
            @Param("times") String times,
            @Param("uid") int uid
    );
}
